note
tonal-note
is a collection of functions to manipulate musical notes in scientific notation
This is part of tonal music theory library.
Usage
import * as note from 'tonal-note'
note.name('bb2')
note.chroma('bb2')
note.enharmonics('C#6')
note.simplify('B#3')
import { name } from 'tonal-note'
['c', 'db3', '2', 'g+', 'gx4'].map(name)
Install
API Documentation
note.midi(note)
⇒ Integer
Get the note midi number
(an alias of tonal-midi toMidi
function)
Kind: static method of note
Returns: Integer
- the midi number or null if not valid pitch
See: midi.toMidi
Param | Type | Description |
---|
note | Array | String | Number | the note to get the midi number from |
Example
note.midi('C4')
note.fromMidi(midi, useSharps)
⇒ String
Get the note name of a given midi note number
(an alias of tonal-midi note
function)
Kind: static method of note
Returns: String
- the note name
See: midi.note
Param | Type | Description |
---|
midi | Integer | the midi note number |
useSharps | Boolean | (Optional) set to true to use sharps instead of flats |
Example
note.fromMidi(60)
note.freq(note)
⇒ Number
Get the frequency of a note
(an alias of the tonal-note package toFreq
function)
Kind: static method of note
Returns: Number
- the frequency
See: freq.toFreq
Param | Type | Description |
---|
note | Array | String | Number | the note to get the frequency |
Example
note.freq('A4')
note.chroma(note)
⇒ Integer
Return the chroma of a note. The chroma is the numeric equivalent to the
pitch class, where 0 is C, 1 is C# or Db, 2 is D... 11 is B
Kind: static method of note
Returns: Integer
- the chroma
Param | Type |
---|
note | String | Pitch |
Example
var note = require('tonal-note')
note.chroma('Cb')
['C', 'D', 'E', 'F'].map(note.chroma)
note.name(n)
⇒ String
Given a note (as string or as array notation) returns a string
with the note name in scientific notation or null
if not valid note
Can be used to test if a string is a valid note name.
Kind: static method of note
Example
var note = require('tonal-note')
note.name('cb2')
['c', 'db3', '2', 'g+', 'gx4'].map(note.name)
note.note()
Deprecated
Kind: static method of note
note.props(note)
⇒ Object
Deprecated
Kind: static method of note
Returns: Object
- the object with note properties or null if not valid note
Param | Type | Description |
---|
note | String | Pitch | the note |
Example
note.props('Db3')
note.props('C#')
note.fromProps(noteProps)
⇒ String
Deprecated
Kind: static method of note
Returns: String
- the note name
- step: a number from 0 to 6 meaning note step letter from 'C' to 'B'
- alt: the accidentals as number (0 no accidentals, 1 is '#', 2 is '##', -2 is 'bb')
- oct: (Optional) the octave. If not present (or undefined) it returns a pitch class
Param | Type | Description |
---|
noteProps | Object | an object with the following attributes: |
Example
note.fromProps({ step: 1, alt: -1, oct: 5 })
note.fromProps({ step: 0, alt: 1 })
note.oct(note)
⇒ Integer
Get the octave of the given pitch
Kind: static method of note
Returns: Integer
- the octave, undefined if its a pitch class or null if
not a valid note
Param | Type | Description |
---|
note | String | Pitch | the note |
Example
note.oct('C#4')
note.oct('C')
note.oct('blah')
note.step(note)
⇒ Integer
Get the note step: a number equivalent of the note letter. 0 means C and
6 means B. This is different from chroma
(see example)
Kind: static method of note
Returns: Integer
- a number between 0 and 6 or null if not a note
Param | Type | Description |
---|
note | String | Pitch | the note |
Example
note.step('C')
note.step('Cb')
note.chroma('Cb')
note.pcFifths(note)
⇒ Integer
Deprecated
Kind: static method of note
Returns: Integer
- the number of fifths to reach that pitch class from 'C'
Param | Type | Description |
---|
note | String | Pitch | the note (can be a pitch class) |
note.alt(note)
⇒ Integer
Get the note alteration: a number equivalent to the accidentals. 0 means
no accidentals, negative numbers are for flats, positive for sharps
Kind: static method of note
Returns: Integer
- the alteration
Param | Type | Description |
---|
note | String | Pitch | the note |
Example
note.alt('C')
note.alt('C#')
note.alt('Cb')
note.pc(n)
⇒ String
Get pitch class of a note. The note can be a string or a pitch array.
Kind: static method of note
Returns: String
- the pitch class
Example
tonal.pc('Db3')
tonal.map(tonal.pc, 'db3 bb6 fx2')
note.enharmonics(note)
⇒ Array
Get the enharmonics of a note. It returns an array of three elements: the
below enharmonic, the note, and the upper enharmonic
Kind: static method of note
Returns: Array
- an array of pitches ordered by distance to the given one
Param | Type | Description |
---|
note | String | the note to get the enharmonics from |
Example
var note = require('tonal-note')
note.enharmonics('C')
note.enharmonics('A')
note.enharmonics('C#4')
note.enharmonics('Db')
note.simplify(note)
⇒ String
Get a simpler enharmonic note name from a note if exists
Kind: static method of note
Returns: String
- the simplfiied note (if not found, return same note)
Param | Type | Description |
---|
note | String | the note to simplify |
Example
var note = require('tonal-note')
note.simplify('B#3')